package com.ctshk.sapp.system.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.rpc.system.dto.MainDataCurrencyListDTO;
import com.ctshk.rpc.system.dto.MainDataCurrencyQueryDTO;
import com.ctshk.rpc.system.req.MainDataCurrencyAddReq;
import com.ctshk.rpc.system.req.MainDataCurrencyListReq;
import com.ctshk.rpc.system.req.MainDataCurrencyUpdateReq;
import com.ctshk.rpc.system.req.MainDataCurrencyUpdateStatusReq;
import com.ctshk.rpc.system.service.IMainDataCurrencyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器 币种
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-29
 */
@Api(value = "主数据币种",tags = "主数据币种")
@RestController
@RequestMapping("/main/data/currency")
public class MainDataCurrencyController extends BaseController {

    @DubboReference
    private IMainDataCurrencyService iMainDataCurrencyService;

    /**
     * 新增币种
     * @param req
     * @return
     */
    @ApiOperation(value="新增币种", notes="新增币种")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "新增币种", operDesc = "新增币种")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid MainDataCurrencyAddReq req){
        TokenUser currentUser = getCurrentUser(getRequest());
        req.setCreateId(currentUser.getId());
        req.setModifiedId(currentUser.getId());
        req.setModifiedName(currentUser.getUsername());
        return iMainDataCurrencyService.add(req);
    }
    /**
     * 编辑币种
     * @param req
     * @return
     */
    @ApiOperation(value="编辑币种", notes="编辑币种")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "编辑币种", operDesc = "编辑币种")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid MainDataCurrencyUpdateReq req){
        TokenUser currentUser = getCurrentUser(getRequest());
        req.setModifiedId(currentUser.getId());
        req.setModifiedName(currentUser.getUsername());
        return iMainDataCurrencyService.update(req);
    }

    /**
     * 修改币种状态
     * @param req
     * @return
     */
    @ApiOperation(value="编辑币种状态", notes="编辑币种状态")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "编辑币种状态", operDesc = "编辑币种状态")
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody @Valid MainDataCurrencyUpdateStatusReq req){
        TokenUser currentUser = getCurrentUser(getRequest());
        req.setModifiedId(currentUser.getId());
        req.setModifiedName(currentUser.getUsername());
        return iMainDataCurrencyService.updateStatus(req);
    }

    /**
     * 查询币种列表
     * @param req
     * @return
     */
    @ApiOperation(value="查询币种列表", notes="查询币种列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询币种列表", operDesc = "查询币种列表")
    @PostMapping("/list")
    public Result<PageResponse<MainDataCurrencyListDTO>> list(@RequestBody @Valid MainDataCurrencyListReq req){
        return Result.success(iMainDataCurrencyService.list(req));
    }

    @ApiOperation(value="查询币种", notes="查询币种")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询币种列表", operDesc = "查询币种列表")
    @PostMapping("/query")
    public Result<MainDataCurrencyQueryDTO> query(@RequestBody @Valid MainDataCurrencyUpdateStatusReq req){
        return iMainDataCurrencyService.query(req);
    }

    @ApiOperation(value="查询币种", notes="查询币种")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询币种列表", operDesc = "查询币种列表")
    @PostMapping("/queryList")
    public Result<List<MainDataCurrencyQueryDTO>> queryList(@RequestBody @Valid List<Long>  req){
        return Result.success(iMainDataCurrencyService.queryList(req));
    }




}
